library(openxlsx)
library(lmerTest)

# Linear mixed model for figure 2B (data access restricted)
Matrice<-read.xlsx("FullPath\\AnalyseMixedModelJournalTime2Filtered1JCRnFullRate.xlsx",sheet=1,startRow=1,colNames=TRUE) # FullPath must be replaced by the full path to the directory where the file is saved
Model<-"JCR1~Authors1LastFull*JournalType+(1|Journal)" # Model
Resultat<-lmer(Model,data=Matrice)
hist(resid(Resultat)) # Display residuals
summary(Resultat)


# Linear mixed model for the two left bars of figure 2C
Matrice<-read.xlsx("FullPath\\AnalyseMixedModelJournalTime2Filtered1JCRnDifference1Full.xlsx",sheet=1,startRow=1,colNames=TRUE) # FullPath must be replaced by the full path to the directory where the file is saved
Model<-"Authors1LastFull~JCR1*JournalType*AuthorsType+(1|Journal)" # Model
Resultat<-lmer(Model,data=Matrice)
hist(resid(Resultat)) # Display residuals
summary(Resultat)

# Linear mixed model for the two right bars of figure 2C
Matrice<-read.xlsx("FullPath\\AnalyseMixedModelJournalTime2Filtered1JCRnDifference2Full.xlsx",sheet=1,startRow=1,colNames=TRUE) # FullPath must be replaced by the full path to the directory where the file is saved
Model<-"Authors1LastFull~JCR1*JournalType*AuthorsType+(1|Journal)" # Model
Resultat<-lmer(Model,data=Matrice)
hist(resid(Resultat)) # Display residuals
summary(Resultat)

# Linear mixed model showing that the difference between the two left bars of figure 2C increases over time
Matrice<-read.xlsx("FullPath\\AnalyseMixedModelJournalTime2Filtered1JCRnDifference1Full.xlsx",sheet=1,startRow=1,colNames=TRUE) # FullPath must be replaced by the full path to the directory where the file is saved
Model<-"Authors1LastFull~JCR1*AuthorsType*Time*JournalType+(1|Journal)" # Model
Resultat<-lmer(Model,data=Matrice)
hist(resid(Resultat)) # Display residuals
summary(Resultat)

# Linear model showing a difference between, on one side, the influence in the relative variations in impact factor (year n - year n-1) over the relative varaitions in the number of articles submitted (year n+1 - year n) and, on the other side, the influence in the relative variations in impact factor (year n - year n-1) over the relative varaitions in the number of published articles used to compute the IF 
Matrice<-read.xlsx("C:\\Users\\Remy Neveu\\Desktop\\Tests_R\\AnalyseEtudeIRM\\AnalyseNatureSoumission.xlsx",sheet=1,startRow=1,colNames=TRUE)
Model<-"RelativeVariation~IF*Group" # Model
Resultat<-glm(Model,data=Matrice,family=gaussian)
hist(resid(Resultat)) # Display residuals
summary(Resultat)



